namespace Library
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Windows.Forms;

    [ToolboxBitmap(typeof(Curve))]
    public class Curve : Control
    {
        private bool _bHaveAction = false;
        private float _CurrentValue = 0f;
        private System.Drawing.Drawing2D.DashStyle _dashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        private Font _font = null;
        private int _LineAlpha = 0xff;
        private Color _LineColor = Color.Black;
        private System.Drawing.Drawing2D.DashStyle _LineStyle = System.Drawing.Drawing2D.DashStyle.Solid;
        private int _LineWidth = 2;
        private int _MaxValue = 200;
        private string _scalename = null;
        private string _sName = "CurveName";
        private Color clrAxisColor = Color.Black;
        private Color clrAxisTextColor = Color.Black;
        private Color clrsCurveColors = Color.Red;
        private Color clrSliceTextColor = Color.Black;
        private Color clrTextColor = Color.Green;
        private IContainer components = null;
        private int intCurveSize = 1;
        private int intFontSize = 9;
        private long m_lend = 0L;
        private long m_lMaxDataPrSerie = 0x270fL;
        private long m_lNoValues = 0L;
        private float[] m_pvalues = new float[0x2710];
        private string strTitle = "曲线图";

        public Curve()
        {
            this.InitializeComponent();
            base.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
        }

        public void AddPoint(float y)
        {
            this.CurrentValue = y;
            this.m_pvalues[(int) ((IntPtr) this.m_lend)] = y;
            this.m_lNoValues += 1L;
            this.m_lend += 1L;
            if (this.m_lend >= this.m_lMaxDataPrSerie)
            {
                this.m_lend = 0L;
                this.m_lNoValues = 0L;
            }
            this.Refresh();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            float left;
            float num5;
            float num6;
            float num7;
            long num11;
            Graphics graphics = pe.Graphics;
            GraphicsPath path = new GraphicsPath();
            Rectangle rect = new Rectangle(new Point(0, 0), new Size(base.ClientSize.Width, base.ClientSize.Height));
            path.AddRectangle(rect);
            Pen pen = null;
            pen = new Pen(Color.FromArgb(this.LineAlpha, this.LineColor));
            pen.Width = this.LineWidth;
            pen.DashStyle = this.DashStyle;
            graphics.DrawPath(pen, path);
            if (pen != null)
            {
                pen.Dispose();
            }
            path.Dispose();
            if (this._font == null)
            {
                this._font = new Font("宋体", (float) this.FontSize, FontStyle.Regular);
            }
            SolidBrush brush = new SolidBrush(this.clrAxisColor);
            Pen pen2 = new Pen(this.AxisColor, 1f);
            for (int i = -2; i < 3; i++)
            {
                graphics.DrawString(((i * this.MaxValue) / 2).ToString(), this._font, brush, (float) rect.Left, (float) ((rect.Top + (rect.Height / 2)) - ((i * rect.Height) / 6)));
                for (int j = 0; j < 60; j += 2)
                {
                    left = rect.Left + (((9 * rect.Width) * j) / 600);
                    num5 = (rect.Top + (rect.Height / 2)) - ((i * rect.Height) / 6);
                    num6 = rect.Left + (((9 * rect.Width) * (j + 1)) / 600);
                    num7 = (rect.Top + (rect.Height / 2)) - ((i * rect.Height) / 6);
                    graphics.DrawLine(pen2, left, num5, num6, num7);
                }
            }
            pen2.Dispose();
            brush.Dispose();
            SolidBrush brush2 = new SolidBrush(this.clrTextColor);
            graphics.DrawString(this.strTitle, this._font, brush2, (float) ((rect.Width / 2) - this.strTitle.Length), (float) (rect.Top + 15));
            graphics.DrawString("当前值： " + this.CurrentValue.ToString(), this._font, brush2, (float) (rect.Left + 5), (float) (rect.Top + 15));
            graphics.DrawString("曲线名称： " + this.sName, this._font, brush2, (float) (rect.Left + 5), (float) (rect.Bottom - 15));
            brush2.Dispose();
            float maxValue = this.MaxValue;
            float num9 = ((float) (rect.Width * 0.9)) / 400f;
            long lNoValues = this.m_lNoValues;
            Pen pen3 = new Pen(this.clrsCurveColors, (float) this.intCurveSize);
            pen3.DashStyle = this.LineStyle;
            if (lNoValues < 400L)
            {
                left = rect.Left;
                num5 = rect.Top + (rect.Height / 2);
                for (num11 = 0L; (num11 < 400L) && (num11 < lNoValues); num11 += 1L)
                {
                    num6 = rect.Left + (num11 * num9);
                    num7 = (rect.Top + (rect.Height / 2)) - ((((this.m_pvalues[(int) ((IntPtr) num11)] * rect.Height) / (2f * maxValue)) * 2f) / 3f);
                    graphics.DrawLine(pen3, left, num5, num6, num7);
                    left = num6;
                    num5 = num7;
                }
            }
            else
            {
                int num12 = 0;
                left = rect.Left;
                num5 = rect.Top + (rect.Height / 2);
                for (num11 = lNoValues - 400L; num11 < lNoValues; num11 += 1L)
                {
                    num6 = rect.Left + (num12 * num9);
                    num7 = (rect.Top + (rect.Height / 2)) - ((((this.m_pvalues[(int) ((IntPtr) num11)] * rect.Height) / (2f * maxValue)) * 2f) / 3f);
                    graphics.DrawLine(pen3, left, num5, num6, num7);
                    num12++;
                    left = num6;
                    num5 = num7;
                }
            }
            pen3.Dispose();
            base.OnPaint(pe);
        }

        [Category("曲线"), Description("坐标系的颜色")]
        public Color AxisColor
        {
            get
            {
                return this.clrAxisColor;
            }
            set
            {
                this.clrAxisColor = value;
                base.Invalidate();
            }
        }

        public bool bHaveAction
        {
            get
            {
                return this._bHaveAction;
            }
            set
            {
                this._bHaveAction = value;
            }
        }

        public float CurrentValue
        {
            get
            {
                return this._CurrentValue;
            }
            set
            {
                this._CurrentValue = value;
            }
        }

        [Category("曲线"), Description("曲线颜色")]
        public Color CurveColor
        {
            get
            {
                return this.clrsCurveColors;
            }
            set
            {
                this.clrsCurveColors = value;
                base.Invalidate();
            }
        }

        [Category("曲线"), Description("曲线线宽")]
        public int CurveSize
        {
            get
            {
                return this.intCurveSize;
            }
            set
            {
                this.intCurveSize = value;
                base.Invalidate();
            }
        }

        [Description("边框风格"), Category("边框")]
        public System.Drawing.Drawing2D.DashStyle DashStyle
        {
            get
            {
                return this._dashStyle;
            }
            set
            {
                this._dashStyle = value;
                base.Invalidate();
            }
        }

        [Category("曲线文本"), Description("数字和文本的字号")]
        public int FontSize
        {
            get
            {
                return this.intFontSize;
            }
            set
            {
                this.intFontSize = value;
                base.Invalidate();
            }
        }

        [Category("边框"), Description("边框线色透明值0~255")]
        public int LineAlpha
        {
            get
            {
                return this._LineAlpha;
            }
            set
            {
                this._LineAlpha = value;
                base.Invalidate();
            }
        }

        [Category("边框"), Description("边框颜色")]
        public Color LineColor
        {
            get
            {
                return this._LineColor;
            }
            set
            {
                this._LineColor = value;
                base.Invalidate();
            }
        }

        [Category("曲线"), Description("曲线风格")]
        public System.Drawing.Drawing2D.DashStyle LineStyle
        {
            get
            {
                return this._LineStyle;
            }
            set
            {
                this._LineStyle = value;
                base.Invalidate();
            }
        }

        [Category("边框"), Description("边框线宽")]
        public int LineWidth
        {
            get
            {
                return this._LineWidth;
            }
            set
            {
                this._LineWidth = value;
                base.Invalidate();
            }
        }

        [Category("曲线"), Description("Y轴最大值")]
        public int MaxValue
        {
            get
            {
                return this._MaxValue;
            }
            set
            {
                this._MaxValue = value;
                base.Invalidate();
            }
        }

        [Description("文本字体"), Category("曲线文本")]
        public Font mFont
        {
            get
            {
                return this._font;
            }
            set
            {
                this._font = value;
                base.Invalidate();
            }
        }

        public string ScaleName
        {
            get
            {
                return this._scalename;
            }
            set
            {
                this._scalename = value;
            }
        }

        [Category("曲线"), Description("曲线名称")]
        public string sName
        {
            get
            {
                return this._sName;
            }
            set
            {
                this._sName = value;
                base.Invalidate();
            }
        }

        [Category("曲线文本"), Description("数字和文本的颜色")]
        public Color TextColor
        {
            get
            {
                return this.clrTextColor;
            }
            set
            {
                this.clrTextColor = value;
                base.Invalidate();
            }
        }

        [Description("图表标题"), Category("曲线")]
        public string Title
        {
            get
            {
                return this.strTitle;
            }
            set
            {
                this.strTitle = value;
                base.Invalidate();
            }
        }
    }
}

